// pages/write_answer/write_answer.js
// 获取应用实例
var app = getApp()
var flag01 = 0
var flag02 = 0
var flag03 = 0
var flag04 = 0
var flag05 = 0

Page({
  data: {
    location: '',
    bold: '',
    italic: '',
    qid:'0',
  },

  onLoad:function(options){
    var tag = options.tag;
    console.log("tag:"+tag);
    this.setData({
      tag:tag,
    })
  },

  inputTitle:function(e){
    var title = e.detail.value; 
    //console.log("title:"+title);
    this.setData({
      title:title,
    })
  },

  inputContent:function(e){
    var content = e.detail.value; 
    //console.log("content:"+content);
    this.setData({
      content:content,
    })
  },

  submitContent:function(e){
    var title = this.data.title;
    var content = this.data.content;
    var userid = getApp().globalData.userid;
    console.log("title:"+title);
    console.log("content:"+content);
    var tag = this.data.tag;
    var mark;
    if(tag=='q'){
      mark = 'subQuestion'
      console.log("mark:"+mark);
    }else if(tag=='e'){
      mark = 'subExperience'
      console.log("mark:"+mark);
    }else if(tag=='r'){
      mark = 'subResource'
      console.log("mark:"+mark);
    }

    wx.request({
      url: 'http://localhost:8080/youYanZaiXian/ForumServlet',
      method: 'POST',
      data:{
        mark:mark,
        title:title,
        content:content,
        userid:userid,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
        'Accept': 'application/json'
      },
      success: (res)=>{
        var suc = res.data.data.suc;
        if(suc==1){
          wx.showToast({
            title: '发表成功',
            icon: 'success',
            duration: 2000
          })
        }else{
          wx.showToast({
            title: '发表失败',
            icon: 'error',
            duration: 2000
          })
        }
      }
    });
  },



  //字体加粗
  fontChange01: function () {
    if (!flag01) {
      flag01 = 1
      this.setData({
        bold: "bold",
        // color01:0
      })
    } else {
      flag01 = 0
      this.setData({
        bold: "",
        // color01:1
      })
    }

    // console.log("加粗")
  },


  // fontChange02:function(){
  //   if(!flag02){
  //     flag02=1
  //     this.setData({
  //       italic:"italic"
  //     })
  //   }
  //     else{
  //       flag02=0
  //       this.setData({
  //         italic:""
  //       })
  //     }
  //   },


  //左对齐
  fontChange03: function () {
    if (!flag03) {
      flag03 = 1
      this.setData({
        location: "left",
        // color02:0
      })
    } else {
      flag03 = 0
      this.setData({
        location: "",
        // color02:1
      })
      // if(flag04==0&&flag05==0){
      //   this.setData({
      //     color02:1
      //   })
      // }
    }
  },

  //居中
  fontChange04: function () {
    if (!flag04) {
      flag04 = 1
      this.setData({
        location: "center",
        // color03:0
      })
    } else {
      flag04 = 0
      this.setData({
        location: "",
        // color03:1
      })
    }
  },

  //右对齐
  fontChange05: function () {
    if (!flag05) {
      flag05 = 1
      this.setData({
        location: "right",
        // color04:0
      })
    } else {
      flag05 = 0
      this.setData({
        location: "",
        // color04:1
      })
    }
  },
})